package n13.second;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.stream.*;

public class S01 {
	public static void main(String[] args) throws IOException  {
		//(1)由数组获取Stream
		String[]xms= {"zhangsan","lisi","wangwu"};
		Stream<String> stream = Arrays.stream(xms);
		//(2)由Stream类的静态方法
		Stream<Integer> stream2 = Stream.of(123, 45, 78);
		Stream<String> stream3 = Stream.of(xms);
		Stream<Integer> iterate = Stream.iterate(0, x->++x); //无限流
		//(3)由Collection接口的默认方法stream()来获取流
		//(3.1)由List来获取
		List<Person>list= new ArrayList<Person>();
		list.add(new Person("zhangsan",20));
		list.add(new Person("lisi",22)); 
		list.add(new Person("wangwu",18));
		Stream<Person> stream4 = list.stream();
		//(3.2)由Set来获取
		Set<Double> set=new HashSet<Double>();
		set.add(1.23);
		set.add(567.8);
		Stream<Double> stream5 = set.stream();
		//(3.3)由Map来获取
		Map<String, String>map=new HashMap<String, String>();
		map.put("Spring", "春季");
		map.put("Summer", "夏季");
		Stream<Entry<String, String>> stream6 = map.entrySet().stream();
		//(4)基本数值类型，专用的有IntStream、LongStream、DoubleStream三个接口
		IntStream of = IntStream.of(123,456,789); //流由123、456、789组成
		IntStream range = IntStream.range(10, 15); //流由10、11、12、13、14组成
		IntStream closed = IntStream.rangeClosed(1, 3); //流由1、2、3组成
		//(5)由其它类的静态方法或实例方法来获取
		Stream<Path> list2 = Files.list(Paths.get("D:/out"));
		Stream<String> lines = Files.lines(Paths.get("D:/out/名言.txt"));
		Stream<String> lines2 = Files.lines(Paths.get("D:/out/名言.txt"), Charset.defaultCharset());
		Pattern p=Pattern.compile(" +");
		Stream<String> splitAsStream = p.splitAsStream("How are you?");
		Random r = new Random();
		IntStream ints = r.ints(); //无限的伪随机int值流
	}

}
